import request from "../../utils/request.ts";
import {message} from 'antd';
import type {AxiosResponse} from 'axios'


//获取科室列表
export const getDepartmentList = async (params: any): Promise<any> => {
    try {
        const res: AxiosResponse<any, any> = await request.get('/department/list', params)
        if (res.data.code === 1) {
            return res.data
        }
        message.error(res.data.msg)
    } catch (err) {
        message.error('获取科室列表失败')
        throw err
    }
}

//批量删除科室
export const delAllDepartment = async (params: any): Promise<any> => {
    try {
        const res: AxiosResponse<any, any> = await request.get('/department/batchdel', params)
        if (res.data.code === 1) {
            message.success(res.data.msg)
            return res.data
        }
        message.error(res.data.msg)
    } catch (err) {
        message.error('批量删除科室失败')
        throw err
    }
}


//删除科室
export const delDepartment = async (params: any): Promise<any> => {
    try {
        const res: AxiosResponse<any, any> = await request.get('/department/del', params)
        if (res.data.code === 1) {
            message.success(res.data.msg)
            return res.data
        }
        message.error(res.data.msg)
    } catch (err) {
        message.error('删除科室失败')
        throw err
    }
}


//根据科室名称查询数据列表
export const getDepartmentSearch = async (params: any): Promise<any> => {
    try {
        const res: AxiosResponse<any, any> = await request.get(`/department/search`, params)
        if (res.data.code === 1) {
            return res.data
        }
        message.error(res.data.msg)
    } catch (err) {
        message.error('查询科室失败')
        throw err
    }
}


//修改科室数据
export const editDepartment = async (params: any): Promise<any> => {
    try {
        const res: AxiosResponse<any, any> = await request.get('/department/edit', params)
        if (res.data.code === 1) {
            message.success(res.data.msg)
            return res.data
        }
        message.error(res.data.msg)
    } catch (err) {
        message.error('修改科室数据失败')
        throw err
    }
}

// 添加科室
export const addDepartment = async (params: any): Promise<any> => {
    try {
        const res: AxiosResponse<any, any> = await request.get('/department/add', params)
        if (res.data.code === 1) {
            message.success(res.data.msg)
            return res.data
        }
        message.error(res.data.msg)
    } catch (err) {
        message.error('添加科室失败')
        throw err
    }
}